package com.xiaotu.lambdaDemo;

/**
 * @Author xiaotu
 * @Description //TODO
 * @Date 2022/3/25 14:44
 * @ClassName TestLambda01
 * @Version 1.0
 *
 * 推导lambda表达式
 *
 * lambda表达式只有在一行代码的情况,才能简化成为一行,,如果有多行用代码块包裹
 * 前提是接口为函数式接口
 *
 * 多个参数也可以去掉参数类型 要去掉,都去掉 加()
 *
 * (a,b)->System.out.println("She is my Lover!");
 *
 **/
public class TestLambda01 {
    //静态内部类
    static class Like1 implements ILike{
        @Override
        public void Love() {
            System.out.println("She is my Lover!");
        }
    }

    public static void main(String[] args) {
        ILike myLove = new myLove();
        myLove.Love();
        ILike like1 = new Like1();
        like1.Love();
        //局部内部类
        class Like3 implements ILike{
            @Override
            public void Love() {
                System.out.println("I like  java !");
            }
        }
        ILike like3 = new Like3();
        like3.Love();
        //匿名内部类
        ILike like4 = new ILike(){
            @Override
            public void Love() {
                System.out.println("I like python!");
            }
        };
        like4.Love();
        //lambda
        ILike like5 = ()->{
            System.out.println("I like lambda!");
        };
        like5.Love();
        //Runnable 的lambda表达式
        new Thread(()->{
            System.out.println(Thread.currentThread().getName()+"你好");
        },"小土").start();

    }
}
//函数式接口
interface ILike{
    void Love();
}
class myLove implements ILike{
    @Override
    public void Love() {
        System.out.println("This is my lover!");
    }
}

